#include "CSocketFactoryImpl.h"
#include <string.h>
#include <stdlib.h>

//客户端初始化 获取handle上下文
int CSocketFactoryImpl::cltSocketInit()
{
        p = NULL;
        len = 0; 
        return 0;
}

//客户端发送报文
int CSocketFactoryImpl::cltSocketSend(unsigned char *buf,int buflen)
{
        p = (unsigned char *)malloc(sizeof(unsigned char)*buflen);
        if(p == NULL){
                return -1;
        }
        memcpy(p, buf, buflen);
        len = buflen;
        return 0;
}

//客户端收报文
int CSocketFactoryImpl::cltSocketRev(unsigned char *buf, int *buflen)
{
        if(buf == NULL || buflen == NULL){
                return -1;
        }
        *buflen = this->len;
        memcpy(buf, this->p, this->len);

        return 0;
}

//客户端释放资源
int CSocketFactoryImpl::cltSocketDestory()
{
        if(p != NULL){
                free(p);
                p = NULL;
                len = 0;
        }
        return 0;
}